#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ri register int
typedef long long ll;
const int N = 101;
int n;
ll k;

struct matrix {
	ll num[N][N];
	matrix() {
		memset(num, 0, sizeof(num));
	}

	friend matrix operator*(const matrix &a, const matrix &b) {
		matrix x;
		for (ri i = 0; i < n; ++i) {
			for (ri j = 0; j < n; j++) {
				for (ri k = 0; k < n; k++) {
					x.num[i][j] += a.num[i][k] * b.num[k][j] % mod;
					x.num[i][j] %= mod;
				}
			}
		}
		return x;
	}
	void print() {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				cout << num[i][j] << " ";
			}
			cout << endl;
		}
	}
} l;

int main() {
	// freopen("testdata.in", "r", stdin);
	// freopen("testdata.out", "w", stdout);
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> l.num[i][j];
		}
	}
	matrix ans;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ans.num[i][j] = (i == j ? 1 : 0);
		}
	}
	while (k) {
		if (k & 1) {
			ans = ans * l;
			k -= 1;
		} else {
			l = l * l;
			k >>= 1;
		}
	}
	ans.print();
	// fclose(stdin);
	// fclose(stdout);
	return 0;
}